package com.maxd.respository;

import com.maxd.model.PayRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface PayRecordRepository extends JpaRepository<PayRecord, String>, JpaSpecificationExecutor<PayRecord> {
    @Transactional
    @Modifying
    @Query("update PayRecord r set r.payStatus = ?2 where r.paySeq = ?1")
    Integer updateStatus(String paySeq, String payStatus);

    @Transactional
    @Modifying
    @Query("update PayRecord r set r.payStatus = '2', r.transactionId = ?2 where r.paySeq = ?1")
    Integer updatePaySuccess(String paySeq, String transactionId);

    @Query(value = "select * from pay_record r where r.pay_status in ('0', '1') " +
            "and r.create_time > date_sub(now(),interval 3 day) " +
            "and r.create_time < date_sub(now(),interval 30 minute) " +
            "order by r.create_time" , nativeQuery = true)
    List<PayRecord> queryWaitCheckList();
}